package com.demo.mdmt.impl;

import com.demo.api.user.domain.TestLimit;
import com.demo.api.user.service.InsertLimitService;
import com.demo.common.enums.ResultCode;
import com.demo.common.response.Result;
import com.demo.mdmt.mapper.TestLimitDao;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author
 * @since
 */
@Service(version = "1.0.0", interfaceClass = InsertLimitService.class, timeout = 120000, retries = 3)
@Slf4j
public class InsertLimitServiceImpl implements InsertLimitService {
  @Autowired
  TestLimitDao testLimitDao;

  @Override
  public Result addTestLimit(TestLimit testLimit) {
    log.info("InsertLimitServiceImpl.addTestLimit 执行写入，参数{}", testLimit);
    int result = 0;
    try {
      result = testLimitDao.insert(toMdmtTestLimit(testLimit));
    } catch (Exception e){
      log.info("{}", e);
      return Result.fail(ResultCode.SYSTEM_ERROR);
    }
    log.info("InsertLimitServiceImpl.addTestLimit 执行写入结束", testLimit);
    return Result.suc(result);
  }

  protected com.demo.mdmt.domain.TestLimit toMdmtTestLimit(com.demo.api.user.domain.TestLimit testLimit){
    com.demo.mdmt.domain.TestLimit testLimitMdmt = new com.demo.mdmt.domain.TestLimit();
    BeanUtils.copyProperties(testLimit, testLimitMdmt);
    return testLimitMdmt;
  }
}
